home *** CD-ROM | disk | FTP | other *** search
/ The Very Best of Atari Inside / The Very Best of Atari Inside 1.iso / sharew / astronom / g_colide / galaxy.lst < prev   
Encoding:
File List  |  1988-11-20  |  5.1 KB  |  185 lines

  1. Rem This program is from Astronomy Magazine December 1988
  2. Rem Article name: Galactic Collisions on Your Computer
  3. Rem Authors: Michael C. Schroeder & Neil Comins
  4. Rem GFA conversion version by James Kajpust
  5. Rem No program copyright listed, program offered free by magazine
  6. Rem
  7. Rem Units used:
  8. Rem    G (universal gravitational constant = 1
  9. Rem    t (time unit T.U.)                  = 1.2 million years
  10. Rem    d (distance D.U.)                   = 500 Parsecs
  11. Rem                                        = 1630 light years
  12. Rem    m (mass unit M.U.)                  = 20 Billion solar masses
  13. Rem The TARGET galaxy is a disk and the INTRUDER galaxy is point.
  14. Rem
  15. Rem ----------------------------------------------------------------
  16. Rem
  17. Dim X(1000),Y(1000),Vx(1000),Vy(1000),Z(1000),Vz(1000)
  18. Cls
  19. Rem The main program
  20. Gosub Input_data
  21. Gosub Init_compute
  22. Gosub Particle_pusher
  23. Gosub Screen_display
  24. Print At(0,0);"Press [Control]+[Shift]+[Enter] to escape ";
  25. Procedure Init_compute
  26.   Cls
  27.   Print At(30,24);"Galaxies in Collision"
  28.   Print At(16,22);"Polar View";
  29.   Print At(54,22);"Edge View";
  30.   Line 0,330,640,330
  31.   Line 320,0,320,360
  32.   Line 0,360,640,360
  33.   Rem Initialize TARGET galaxy mass, position and velocity.
  34.   M1=5
  35.   X1=150
  36.   Y1=100
  37.   Vx1=0
  38.   Vy1=0
  39.   Z1=0
  40.   Vz1=0
  41.   Sf2=2
  42.   Rem Scale INTRUDER galaxy mass, position and velocity.
  43.   Time=0
  44.   M2=M2*M1
  45.   X2=X2+X1
  46.   Y2=Y2+Y1
  47.   Z2=Z2+Z1
  48.   Rem Set up initial load
  49.   Rem Place stars in concentric rings from R=10 to R=30 at intervals of dr.
  50.   For Ir=1 To Nrr
  51.     R=10+(Ir-1)*Dr
  52.     V=Sqr(M1/R)
  53.     Th=(0.5*V/R)*(180/Pi)
  54.     If R=10 Then
  55.       V=0.9*V
  56.     Endif
  57.     For It=1 To Nrs
  58.       T=(It-1)*360/Nrs
  59.       T1=Pi*(T-Th)/180
  60.       I=I+1
  61.       Rem Initialize star positions
  62.       X(I)=R*Cos(T/57.2958)+150
  63.       Y(I)=R*Sin(T/57.2958)+100
  64.       Vz(I)=0
  65.       Z(I)=0
  66.       Rem Initialize star velocities to place them in circular orbits about
  67.       Rem the TARGET galaxy
  68.       Vx(I)=-V*Sin(T1)
  69.       Vy(I)=V*Cos(T1)
  70.     Next It
  71.   Next Ir
  72.   Gosub Screen_display
  73. Return
  74. Procedure Particle_pusher
  75.   For K=1 To Ntspr
  76.     For J=1 To 1
  77.       For I=1 To Ns
  78.         Rem Determine the force on a star due to the galactic centers.
  79.         Rem SF2 below, called the softening factor is used to prevent
  80.         Rem overflows during force calculations.  SF2 is assigned a value
  81.         Rem above.  Should be small as possible to better approximate
  82.         Rem a true 1/r**2 force.
  83.         R1=M1/((X(I)-X1)^2+(Y(I)-Y1)^2+(Z(I)-Z1)^2+2+Sf2)^1.5
  84.         R2=M2/((X(I)-X2)^2+(Y(I)-Y2)^2+(Z(I)-Z2)^2+2+Sf2)^1.5
  85.         Rem calculate stars x,y,z accelerations
  86.         Ax=R1*(X1-X(I))+R2*(X2-X(I))
  87.         Ay=R1*(Y1-Y(I))+R2*(Y2-Y(I))
  88.         Az=R1*(Z1-Z(I))+R2*(Z2-Z(I))
  89.         Rem Update star positions and velocities using a time centered
  90.         Rem leap-frog algorithm
  91.         Vx(I)=Vx(I)+Ax
  92.         Vy(I)=Vy(I)+Ay
  93.         Vz(I)=Vz(I)+Az
  94.         X(I)=X(I)+Vx(I)
  95.         Y(I)=Y(I)+Vy(I)
  96.         Z(I)=Z(I)+Vz(I)
  97.       Next I
  98.       Rem Update positions and velocities of the galactic centers
  99.       Rr=((X1-X2)^2+(Y1-Y2)^2+(Z1-Z2)^2+Sf2)^1.5
  100.       Ax=(X2-X1)/Rr
  101.       Ay=(Y2-Y1)/Rr
  102.       Az=(Z2-Z1)/Rr
  103.       Vx1=Vx1+M2*Ax
  104.       Vy1=Vy1+M2*Ay
  105.       Vz1=Vz1+M2*Az
  106.       Vx2=Vx2-M1*Ax
  107.       Vy2=Vy2-M1*Ay
  108.       Vz2=Vz2-M1*Az
  109.       X1=X1+Vx1
  110.       Y1=Y1+Vy1
  111.       Z1=Z1+Vz1
  112.       X2=X2+Vx2
  113.       Y2=Y2+Vy2
  114.       Z2=Z2+Vz2
  115.       Time=Time+1
  116.     Next J
  117.     Gosub Screen_display
  118.   Next K
  119. Return
  120. Procedure Screen_display
  121.   Rem Calculate center of mass of system for use of center of output display
  122.   Xc=(M1*X1+M2*X2)/(M1+M2)
  123.   Yc=(M1*Y1+M2*Y2)/(M1+M2)
  124.   Zc=(M1*Z1+M2*Z2)/(M1+M2)
  125.   Rem Calculate position of galactic centers and display on screen
  126.   Xx1=(X1-Xc)
  127.   Yy1=(Y1-Yc)
  128.   Zz1=(Z1-Zc)
  129.   Xx2=(X2-Xc)
  130.   Yy2=(Y2-Yc)
  131.   Zz2=(Z2-Zc)
  132.   Circle Xx1+160,Yy1+160,4
  133.   Circle Xx1+480,2*Zz1+160,4
  134.   Circle Xx2+160,Yy2+160,4
  135.   Circle Xx2+480,2*Zz2+160,4
  136.   Rem put stars on screen
  137.   For I=1 To Ns
  138.     Xp=(X(I)-Xc)
  139.     Yp=(Y(I)-Yc)
  140.     Zp=2*(Z(I)-Zc)
  141.     Plot Xp+160,Yp+160
  142.     Plot Xp+480,Zp+160
  143.   Next I
  144.   Print At(24,25);"Time = ";
  145.   Print Using "###.#",Time*1.2;
  146.   Print " millions of years";
  147. Return
  148. Rem ------------------------------------------------------
  149. Procedure Input_data
  150.   Input "Do you wish to use stored data (y/n)?";A$
  151.   If A$="n" Or A$="N" Then
  152.     Gosub Request_data
  153.   Else
  154.     Gosub Stored_data
  155.   Endif
  156. Return
  157. Procedure Stored_data
  158.   Nrr=8
  159.   Nrs=10
  160.   Ns=Nrr*Nrs
  161.   Dr=40/(Nrr-1)
  162.   M2=0.25
  163.   X2=40
  164.   Y2=10
  165.   Z2=10
  166.   Vx2=-1
  167.   Vy2=0
  168.   Vz2=0
  169.   Ntspr=1200
  170. Return
  171. Procedure Request_data
  172.   Input "Input the number of rings of stars in the TARGET galaxy ";Nrr
  173.   Input "Input the number of stars per ring in the TARGET galaxy";Nrs
  174.   Ns=Nrr*Nrs
  175.   Dr=40/(Nrr-1)
  176.   Print
  177.   Input "Input mass fraction of INTRUDER galaxy in unit of the taget galaxy mass ";M24
  178.   Print
  179.   Input "Input the initial X, Y, and Z coordinates of the INTRUDER galaxy ";X2,Y2,Z2
  180.   Print
  181.   Input "Input the initial X, Y, and Z velocities of the INTRUDER galaxy ";Vx2,Vy2,Vz2
  182.   Print
  183.   Input "Input the number of time steps for this run ";Ntspr
  184. Return
  185.